<template>
  <div>
    <!--  中间  -->
    <div class="selece">
      <div><img src="../assets/ico@1x1.png" alt=""></div>
      <p>注册</p>
      <input type="tel" placeholder="请输入您的手机号" v-model="telephone">
      <input type="text" placeholder="请填写您的邀请码" v-model="inviteCode">
      <button v-on:click="codeInvite">获取短信验证码</button>
      <p>注册即视为同意XXX的用户协议</p>
    </div>
      <alertTip v-if="showAlert" @closeTip="go()" :alertText="alertText"></alertTip>

  </div>
</template>
<script>
  import Vue from 'vue';
  import Mint from 'mint-ui';
  import 'mint-ui/lib/style.css';
  import wx from 'weixin-js-sdk'
  import { wxHttpTool,wx_config, http_getParam, get_shopQrcoe,wx_share,wx_hideAllMenu } from '../components/httpUtil/httpUtil'
  import {msg_10046} from '../message/msg_10046'

  Vue.use(Mint);
  export default {
    name: "Register",
    data() {
      return {
        telephone: "",
        inviteCode: ''
      }
    },
    methods: {
      alertTip(msg) {
        this.showAlert = true;
        this.alertText = msg;
      },
      go() {
        this.showAlert = false
      },
      codeInvite() {
        const jsonValue = JSON.stringify({
          'c': '10016',
          'p': {
//            'userId': JSON.parse(window.localStorage.data).id, // 用户ID
//            'tokenId': token(),
            'qrCode': this.inviteCode  // 邀请码
//            'qrCode': 'tPgWMC5AVW'
          }
        });
        this.$http.post(api + '/qqs.us', jsonValue).then((res) => {
          console.log(res);
          const data = res.data.p;
          if (data.isTrue === true) {
            this.huoQ();
          } else {
            alert(data.errorMsg);
          }
        }, (res) => {
          this.alertTip("网络错误");
          this.go = function(){
             this.showAlert = false;
          }
          // alert('网络错误');
        })
      },
      huoQ: function () {
        const tel = /^1[34578]\d{9}$/;
        if (!tel.test(this.telephone)) {
          this.alertTip("手机格式不正确");
          this.go = function(){
             this.showAlert = false;
          }
          // alert('手机格式不正确')
          this.telephone = ''
        } else {
          localStorage.setItem("tlp", this.telephone)
          this.$router.push("/fxRegisterCode")
          const jsonValue = JSON.stringify({
            "c": "10003",
            "p": {
              "mobile": this.telephone,
            }
          })
          this.$http.post(api + '/qqs.us', jsonValue)
            .then((response) => {
              console.log(response)
            })
            .catch((error) => {
              console.log(error);
            });
        }
      }
    },
    created(){
      wxHttpTool.wxAuthor(this, function (varRet, varJson, varThis = this) {
        if (varRet == -1) {
          varThis.alertTip('网络错误');
          varThis.go = function () {
            varThis.showAlert = false;
          }

        }
        // 关注钱应该判断下是否已经关注过了
        msg_10046.send(varThis,msg_10046.entity(),function(varThis,res){
          varThis.wxlist=res.data.p.sign
          wx_config(varThis.wxlist);
          varThis.hideLoading();
          wx_hideAllMenu();
          wx.hideMenuItems({
            //禁用单独分享朋友圈QQ空间等功能
            menuList: ["menuItem:share:timeline","menuItem:share:QZone","menuItem:share:qq"] // 要隐藏的菜单项，所有menu项见附录3
          });
        })


      },this.type)
    }
  }
</script>
<style scoped lang="scss">
  .mint-header {
    background: black;
  }

  .selece {
    width: 100%;
    background: #ffffff;
    text-align: center;
    div {
      width: 144px;
      height: 144px;
      margin: 0 auto;
      margin-top: 114px;
      border-radius: 50%;
      border: 1px solid #dcdcdc;
      position: relative;
      img {
        position: absolute;
        width: 86px;
        height: 84px;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
      }
    }
    p:nth-of-type(1) {
      font-size: 24px;
      text-align: center;
      margin-top: 30px;
      color: #3b3b43;
    }
    input {
      width: 80%;
      text-align: center;
      padding-bottom: 26px;
      border: none;
      outline: none;
      border-bottom: 1px solid #dcdcdc !important;
      font-size: 26px;
      margin-top: 46px;
      -webkit-appearance: none;
    }
    input:hover {
      border: #ffffff;
    }
    button {
      width: 73%;
      height: 74px;
      border: none;
      border-radius: 30px;
      font-size: 28px;
      color: #FFFFFF;
      text-align: center;
      margin-top: 51px;
      outline: none;
      background: url("../assets/btn_pay@1x.png");
      background-size: cover;
    }
    p:nth-of-type(2) {
      font-size: 20px;
      color: #a1a1a1;
      margin-top: 36px;
    }
  }
</style>
